/**
 * Copyright ©2012-2018 HopeHaiyang Corporation, All Rights Reserved
 * http://www.wuhanhope.com
 */
package hope.platform.data.web;

import hope.platform.data.domain.Schedule;
import hope.platform.data.server.data.header.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * class info
 *
 * @author hujia
 *         Create at 2018/7/25 16:08
 */
@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    @RequestMapping(method = RequestMethod.POST)
    public Schedule add(@RequestBody Schedule schedule) throws Exception {
        return scheduleService.addSchedule(schedule);
    }

    @RequestMapping(method = RequestMethod.PUT)
    public Schedule update(@RequestBody Schedule schedule) throws Exception {
        return scheduleService.updateSchedule(schedule);
    }

    @RequestMapping(value = "/all/{pageNumber}/{pageSize}/{sortType}", method = RequestMethod.GET)
    public Page<Schedule> findAll(@PathVariable int pageNumber,
                                  @PathVariable int pageSize,
                                  @PathVariable String sortType) throws Exception {
        return scheduleService.findAll(PageRequest.of(pageNumber, pageSize, Sort.Direction.DESC, sortType));

    }

}
